<?php
$section = isset($_POST["section"]) ? $_POST["section"] : null;

$query = "SELECT c.id, si.name, c.block, c.language, c.visible, c.html ".
		 "FROM content c ".
		 "LEFT JOIN section_info si ON si.section_id = c.section_id AND si.language = '$lang' ";
if (!empty($section)) {
	$query .= "WHERE si.section_id = '$section' ";
}
$query .= "ORDER BY si.name, c.block";

if (!$res1 = $db->runQuery($query)) {
	$content->assign("message", "Error de MySQL: ".$db->getErrorDescription());
} else {
	if (!$db->getRowCount($res1)) {
		$content->assign("message", "La consulta no ha devuelto resultados.");
	} else {
		$data = array();
		while ($row1 = $db->getRow($res1)) {
			$data[] = array(
				"section" => utf8_encode($row1["name"]),
				"block" => $row1["block"],
				"language" => $row1["language"],
				"visible" => $row1["visible"],
				"html" => substr(str_replace("\r\n", "", htmlspecialchars(utf8_encode($row1["html"]))), 0, 40)."...",
				"editUrl" => Utils::generateSEOUrl($lang, "content", "edit", $row1["id"])
			);
		}
		$content->assign("data", $data);
	}
}

echo $content->fetch("content-table.tpl");
exit;
?>
